<?php
namespace Admin\Controller;
use Think\Controller;
class NewsController extends Controller {
    public function news(){
    	$news=D('News');
    	$list=$news->select();
    	//var_dump($list);
    	$count = $news->count();
        $Page       = new \Think\Page($count,2);//继承
        $show       = $Page->show();//展示
        $list = $news->limit($Page->firstRow.','.$Page->listRows)->select();
       
        $this->assign('count',$count);
        $this->assign('page',$show);
        $this->assign('list',$list);
        //var_dump($list);exit;


    	$this->assign('list',$list);
    	$this->display(); 
    }

    public function newsadd(){

       $news=D('News');
           if(IS_POST){    
            $data['title']=I('title');
    		$data['content']=I('content');
    		$data['pubtime']=time();
    		$data['pub_master']='老板';	
        if(!$news->create($data)){
                echo $news->getError();
                exit;
            }else
            {	
                if($news->add())
                {
                    $this->success('新增成功！',U('/admin/news/news',3));
                	
                }else
                {
                    $this->error('新增失败！');
                }

            }

}
    	$this->display(); 
    }
}